package com.lbs.jiepiaisi.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView.Adapter;
import android.support.v7.widget.RecyclerView.ViewHolder;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;

import com.amap.api.services.core.PoiItem;
import com.amap.api.services.core.SuggestionCity;
import com.lbs.jiepiaisi.R;
import com.lbs.jiepiaisi.activity.AccountChaseCarAcitivty;
import com.lbs.jiepiaisi.activity.AccountStartNaviActivity;
import com.lbs.jiepiaisi.bean.TrackEntity;
import com.lbs.jiepiaisi.bean.WeiZhangEntity;
import com.lbs.jiepiaisi.utils.Constant;

import java.util.ArrayList;
import java.util.List;

/**
 *
 * 时间：2018/1/09 18:38
 * 作用：poi查询
 */

public class LocationListAdapter extends Adapter<ViewHolder> {
    private static final int TYPE_ITEM = 0;
    private Context context;
    List<PoiItem> listItem;




    public LocationListAdapter(Context context, List<PoiItem> listItem) {
        this.context = context;
        this.listItem = listItem;
    }

    public interface OnItemClickListener {
        void onItemClick(View view, int position);

        void onItemLongClick(View view, int position);
    }

    private OnItemClickListener onItemClickListener;

    public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
        this.onItemClickListener = onItemClickListener;
    }

    @Override
    public int getItemCount() {
        return listItem.size();
    }

    @Override
    public int getItemViewType(int position) {
        return TYPE_ITEM;
    }

    /**
     * 创建新View，被LayoutManager所调用
     */
    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.list_item_location, parent,
                false);


        return new ItemViewHolder(view);
    }

    /**
     * 把现在的数据绑定到原有的viewHolder之上
     */
    @Override
    public void onBindViewHolder(final ViewHolder holder, int position) {
        final int sel = position;

        ((ItemViewHolder) holder).tv_location.setText(listItem.get(position).getTitle());
        ((ItemViewHolder) holder).tv_address.setText(listItem.get(position).getDistance()+ "m " + listItem.get(position).getSnippet());
        ((ItemViewHolder) holder).btn_way.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                if(onItemClickListener != null){
                    onItemClickListener.onItemClick(v,sel);
                }
            }
        });


    }


    static class ItemViewHolder extends ViewHolder {
        TextView tv_location;
        TextView tv_address;
        Button btn_way;

        public ItemViewHolder(View view) {
            super(view);
            tv_location = (TextView) view.findViewById(R.id.tv_location);
            tv_address = (TextView) view.findViewById(R.id.tv_address);
            btn_way = (Button) view.findViewById(R.id.btn_way);
        }
    }


}
